﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="menetlusinfo_v3_menetlused", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(MenetlusinfoV3Menetlused))]
    public class MenetlusinfoV3MenetlusedSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IMenetlusinfoV3Menetlused clazz;
        
        public MenetlusinfoV3MenetlusedSerializer(IMenetlusinfoV3Menetlused clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            for (int x = 0; ((clazz.Dokumendid != null) 
                        && (x < clazz.Dokumendid.Count)); x = (x + 1)) {
                if (clazz.Dokumendid[x]!=null) {
                    Writer.WriteStartElement("dokumendid");
                    global::Xtee.Core.SerializationMetadata metaDokumendid = this.GetMetaData(clazz.Dokumendid[x]);
                    Writer.WriteTypeAttribute(metaDokumendid.TypeQualifiedName.Namespace, metaDokumendid.TypeQualifiedName.Name);
                    metaDokumendid.NewSerializer(clazz.Dokumendid[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
            for (int x = 0; ((clazz.Hoiatused != null) 
                        && (x < clazz.Hoiatused.Count)); x = (x + 1)) {
                if (clazz.Hoiatused[x]!=null) {
                    Writer.WriteStartElement("hoiatused");
                    global::Xtee.Core.SerializationMetadata metaHoiatused = this.GetMetaData(clazz.Hoiatused[x]);
                    Writer.WriteTypeAttribute(metaHoiatused.TypeQualifiedName.Namespace, metaHoiatused.TypeQualifiedName.Name);
                    metaHoiatused.NewSerializer(clazz.Hoiatused[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
            for (int x = 0; ((clazz.Maarused != null) 
                        && (x < clazz.Maarused.Count)); x = (x + 1)) {
                if (clazz.Maarused[x]!=null) {
                    Writer.WriteStartElement("maarused");
                    global::Xtee.Core.SerializationMetadata metaMaarused = this.GetMetaData(clazz.Maarused[x]);
                    Writer.WriteTypeAttribute(metaMaarused.TypeQualifiedName.Namespace, metaMaarused.TypeQualifiedName.Name);
                    metaMaarused.NewSerializer(clazz.Maarused[x]).WriteXml(Writer);
                    Writer.WriteEndElement();
                }
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="dokumendid") {
                clazz.Dokumendid = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Dokument>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "dokumendid")); ) {
                    if ((Reader.IsElementNil() == false)) {
                        global::Xtee.Core.SerializationMetadata metaDokumendid = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Dokument>(Reader, "menetlusinfo_v3_dokument", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Dokument item = metaDokumendid.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Dokument>();
                        clazz.Dokumendid.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("dokumendid");
                            metaDokumendid.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    else {
                        clazz.Dokumendid.Add(null);
                        Reader.Skip();
                    }
                }
            }
            if (Reader.LocalName=="hoiatused") {
                clazz.Hoiatused = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Hoiatus>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "hoiatused")); ) {
                    if ((Reader.IsElementNil() == false)) {
                        global::Xtee.Core.SerializationMetadata metaHoiatused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Hoiatus>(Reader, "menetlusinfo_v3_hoiatus", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Hoiatus item = metaHoiatused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Hoiatus>();
                        clazz.Hoiatused.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("hoiatused");
                            metaHoiatused.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    else {
                        clazz.Hoiatused.Add(null);
                        Reader.Skip();
                    }
                }
            }
            if (Reader.LocalName=="maarused") {
                clazz.Maarused = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Maarus>();
                for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                            && (Reader.LocalName == "maarused")); ) {
                    if ((Reader.IsElementNil() == false)) {
                        global::Xtee.Core.SerializationMetadata metaMaarused = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Maarus>(Reader, "menetlusinfo_v3_maarus", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Maarus item = metaMaarused.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IMenetlusinfoV3Maarus>();
                        clazz.Maarused.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("maarused");
                            metaMaarused.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    else {
                        clazz.Maarused.Add(null);
                        Reader.Skip();
                    }
                }
            }
        }
    }
}
